#!/bin/bash 
empty_field()
{	 
	for ((i=0;i<100;i++))
		do
			array[i]=" . ";
		done	
}
field()
{	
	for ((x=0;x<=10;x++));do
		if [ $x == 0 ];then
			echo "  0  1  2  3  4  5  6  7  8  9 ";
		else
			for((y=0;y<=10;y++));do
				if [ $y == 0 ];then					
					let temp=$x-1;
					echo -n $temp;
				else
					echo -n "${array[10*(x-1)+(y-1)]}"
				fi
			done			
			echo ""
		fi		
	done	
}
empty_field;
	
for coordinates in $@;do
	start_x=${coordinates:0:1}
	start_y=${coordinates:1:1}
	finish_x=${coordinates:2:1}	
	finish_y=${coordinates:3:1}
	
	if [[ "$coordinates" =~ ^[0-9]{4}$  ]] && [[ $start_x == $finish_x || $start_y == $finish_y ]];then
	
		for((i=$start_x;i <= $finish_x;i++));do
			for((j=$start_y;j <= $finish_y;j++));do
				array[10*i+j]=" X "; 
			done				
		done
		
		else echo "Wrong format!!!"
	fi
done

field;
exit 0;
